﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DotNetLib.Windows.Forms;

namespace DotNetLib.Sample.Windows
{
  public partial class ProgressDialogSample : UserControl
  {
    public ProgressDialogSample()
    {
      this.InitializeComponent();
    }

    private void progressDialogSample1_Click(object sender, EventArgs e)
    {
      this.progressDialog1.RunWorker(FindForm());
      MessageBoxHelper.Show(this, "Finished!");
    }

    private void progressDialog1_DoWork(object sender, DoWorkEventArgs e)
    {
      System.Threading.Thread.Sleep(10000);
    }

    private void progressDialogSample2_Click(object sender, EventArgs e)
    {
      this.progressDialog2.RunWorker(FindForm());
      MessageBoxHelper.Show(this, "Finished!");
    }

    private void progressDialog2_DoWork(object sender, DoWorkEventArgs e)
    {
      DateTime toStop = DateTime.Now.AddHours(1);
      for (DateTime now = DateTime.Now; now < toStop; now = DateTime.Now)
      {
        if (this.progressDialog2.CancellationPending)
        {
          e.Cancel = true;
          break;
        }
        else
        {
          System.Threading.Thread.Sleep(1000);
        }
      }
    }

    private void commandLink1_Click(object sender, EventArgs e)
    {
      this.label1.FormatText("stupid", "bastard");
    }
  }
}
